#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define int long long
#define F first
#define S second
// void dijkstra(int sc){
// deque<int> q;
// q.push_front(sc);
// dist[sc]=0;
// while(!q.empty()){
// int cur_node = q.front();
// q.pop_front();
// int cur_dist= dist[cur_node];
// for(auto v : g[cur_node]){
// if(cur_dist+v.S<dist[v.F]){
// dist[v.F]=cur_dist+v.S;
// if(v.S==1)q.push_back(v.F);
// else q.push_front(v.F);
// }
// }
// }
// }
signed main(){
IOS
int t;
cin>>t;
while(t--){
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
cin>>a[i];
vector<pair<int,int>> ans,cur;
for(int i=0;i<n;i++){
if(i==0){
// cur.push_back(make_pair(0,a[0]));
// ans.push_back(make_pair(a[0],0));
}
else{
if(a[i]<a[i-1]){
cur.push_back(make_pair(i,a[i-1]));
ans.push_back(make_pair(a[i-1],i));
cur.push_back(make_pair(i,a[i]));
ans.push_back(make_pair(a[i],i));
}
}
if(i==n-1){
cur.push_back(make_pair(i+1,a[i]));
ans.push_back(make_pair(a[i],i+1));
// cur.push_back(make_pair(i+1,0));
// ans.push_back(make_pair(0,i+1));
}
// for(auto v:cur){
// cout<<v.F<<v.S<<" ";
// }
// for(auto v:ans){
// cout<<v.F<<v.S<<" ";
// }
// cout<<"\n";
}
sort(ans.begin(),ans.end());
sort(cur.begin(),cur.end());
// for(auto v:ans){
// cout<<v.F<<v.S<<" ";
// }
// cout<<"\n";
// for(auto v:cur){
// cout<<v.F<<v.S<<" ";
// }
// cout<<"\n";
bool check=true;
for(int i=0;i<cur.size();i++){
// cout<<cur[i].F<<ans[i].F<<"\n";
if(cur[i].F!=ans[i].F||cur[i].S!=ans[i].S){
check=false;
// cout<<"hi"<<i<<"\n";
}
}
if(check){
cout<<"YES"<<"\n";
}
else
cout<<"NO"<<"\n";
}
}
118A - String Task | 236A - Boy or Girl |
271A - Beautiful Year | 520B - Two Buttons |
231A - Team | 479C - Exams |
1030A - In Search of an Easy Problem | 158A - Next Round |
71A - Way Too Long Words | 160A - Twins |
1A - Theatre Square | 1614B - Divan and a New Project |
791A - Bear and Big Brother | 1452A - Robot Program |
344A - Magnets | 96A - Football |
702B - Powers of Two | 1036A - Function Height |
443A - Anton and Letters | 1478B - Nezzar and Lucky Number |
228A - Is your horseshoe on the other hoof | 122A - Lucky Division |
1611C - Polycarp Recovers the Permutation | 432A - Choosing Teams |
758A - Holiday Of Equality | 1650C - Weight of the System of Nested Segments |
1097A - Gennady and a Card Game | 248A - Cupboards |
1641A - Great Sequence | 1537A - Arithmetic Array |